import { LoveTaskCommentItem } from "./LoveTaskCommentItem";
import { GBox } from "../../../../../com/mui/containers/GBox";
import { GBoxDirection } from "../../../../../com/mui/containers/globalVariable/GBoxDirection";
import { ObjectPool } from "../../../../../com/gengine/utils/pools/ObjectPool";
import { LoveTaskCommentInfo } from "../../../model/loveTask/LoveTaskCommentInfo";
//class LoveTaskCommentList
    
    export  class LoveTaskCommentList /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.initUI();
            return;
        }

        protected onSelectedChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=arg1.target as LoveTaskCommentItem;
            if (loc1) 
            {
                if (loc1.selected) 
                {
                    if (this._lastSelected && !(this._lastSelected == loc1) && this._lastSelected.selected) 
                    {
                        this._lastSelected.selected = false;
                    }
                    this._lastSelected = loc1;
                }
                else if (this._lastSelected == loc1) 
                {
                    this._lastSelected = null;
                }
            }
            return;
        }

        protected initUI(): void
        {
            this._commentList = new GBox();
            this._commentList.x = 20;
            this._commentList.y = 5;
            this._commentList.direction = GBoxDirection.VERTICAL;
            addChild(this._commentList);
            return;
        }

        public updateData(arg1: Array<any>): void
        {
            var loc1=0;
            var loc3=null;
            var loc4=null;
            var loc2=arg1.length;
            while (loc1 < loc2) 
            {
                loc4 = arg1[loc1];
                (loc3 = ObjectPool.getObject(LoveTaskCommentItem)).updateData(loc4);
                loc3.addEventListener(flash.events.Event.CHANGE, this.onSelectedChangeHandler);
                this._commentList.addChild(loc3);
                ++loc1;
            }
            this._commentList.invalidate();
            if (this._commentList.numChildren > 0) 
            {
                this._lastSelected = this._commentList.getChildAt(0) as LoveTaskCommentItem;
                this._lastSelected.selected = true;
            }
            return;
        }

        public dispose(): void
        {
            var loc1=null;
            while (this._commentList.numChildren > 0) 
            {
                loc1 = this._commentList.getChildAt(0) as LoveTaskCommentItem;
                loc1.dispose();
                loc1.removeEventListener(flash.events.Event.CHANGE, this.onSelectedChangeHandler);
                ObjectPool.disposeObject(loc1, LoveTaskCommentItem);
                this._commentList.removeChild(loc1);
            }
            return;
        }

        public get selectedData(): LoveTaskCommentInfo
        {
            if (this._lastSelected && this._lastSelected.selected) 
            {
                return this._lastSelected.data as LoveTaskCommentInfo;
            }
            return null;
        }

        public /* override */ get height(): number
        {
            return this._commentList.numChildren * 30;
        }

        /* internal */ /* var */_commentList: GBox;

        /* internal */ /* var */_lastSelected: LoveTaskCommentItem;
    }
